// https://www.acwing.com/problem/content/submission/code_detail/11704397/
// 26176 KB 2123 ms
#include <bits/stdc++.h>
using namespace std;
const int M = 60;
struct node {
  int id, score, type;
  bool operator<(const node &t) const {
    if (score == t.score) {
      if (type == t.type)
        return id > t.id;
      else
        return type > t.type;
    } else
      return score < t.score;
  }
};
priority_queue<node> pq;
queue<node> q;
unordered_set<int> del[M];
int num[M], n, m;
vector<int> res[M];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  for (int i = 1; i <= n; ++i) {
    int id, score;
    cin >> id >> score;
    for (int j = 0; j < m; ++j) pq.push({id, score, j});
  }
  int t;
  cin >> t;
  while (t--) {
    int op;
    cin >> op;
    if (op < 3) {
      int type, id;
      cin >> type >> id;
      if (op == 1) {
        int score;
        cin >> score;
        pq.push({id, score, type});
      } else
        del[type].insert(id);
    } else {
      int k;
      cin >> k;
      for (int i = 0; i < m; ++i) {
        cin >> num[i];
        res[i].clear();
      }
      while (pq.size() && k) {
        auto [id, score, type] = pq.top();
        pq.pop();
        if (auto it = del[type].find(id); it != del[type].end()) {
          del[type].erase(id);
          continue;
        } else {
          q.push({id, score, type});
          if (num[type]) {
            res[type].push_back(id);
            k--;
            num[type]--;
          }
        }
      }
      while (q.size()) {
        pq.push(q.front());
        q.pop();
      }
      for (int i = 0; i < m; ++i) {
        if (res[i].size())
          for (auto el : res[i]) cout << el << ' ';
        else
          cout << -1;
        cout << endl;
      }
    }
  }
}
